package cc.yaomm.service.basic.controller.business.user;

import cc.yaomm.common.basic.domain.Response;
import cc.yaomm.service.basic.controller.business.BaseAdminController;
import cc.yaomm.service.basic.controller.business.user.biz.RoleBiz;
import cc.yaomm.service.basic.controller.business.user.vo.RoleParamVO;
import cc.yaomm.service.basic.controller.business.user.vo.RoleResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * Created by XQL on 2021/6/9.
 */
@RestController
@RequestMapping("${apps.biz}/role")
@Api(tags = "角色接口")
@Slf4j
public class RoleController extends BaseAdminController {

    @Autowired
    private RoleBiz roleBiz;

    @PostMapping("list")
    @ApiOperation(value = "分页查询角色列表", notes = "分页查询角色列表")
    public Response<List<RoleResultVO>> list(@RequestBody @Valid RoleParamVO paramVO) {
        return Response.success(roleBiz.findPage(paramVO));
    }

    @PostMapping("count")
    @ApiOperation(value = "统计查询角色列表", notes = "统计查询角色列表")
    public Response<Integer> count(@RequestBody @Valid RoleParamVO paramVO) {
        return Response.success(roleBiz.countPage(paramVO));
    }

    @PostMapping({"create", "edit"})
    @ApiOperation(value = "新增/编辑角色", notes = "新增/编辑角色")
    @Validated(RoleParamVO.Edit.class)
    public Response<Integer> save(@RequestBody @Valid RoleParamVO paramVO) {
        roleBiz.save(paramVO);
        return Response.success();
    }

    @PostMapping("lock")
    @ApiOperation(value = "锁定/解锁角色", notes = "锁定/解锁角色")
    @Validated(RoleParamVO.Lock.class)
    public Response<Void> lock(@RequestBody @Valid RoleParamVO paramVO) {
        roleBiz.lock(paramVO);
        return Response.success();
    }
}
